package com.xc.smart.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xc.smart.annotation.Login;
import com.xc.smart.annotation.LoginUser;
import com.xc.smart.entity.Img;
import com.xc.smart.entity.User;
import com.xc.smart.mapper.ImgMapper;
import com.xc.smart.utlis.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author mtl
 * 2021/6/11
 */
@RestController
@RequestMapping("/img")
public class ImgController {

    @Value("${web.upload-path}")
    private  String path;

    @Autowired
    ImgMapper imgMapper;

    @Login
    @ResponseBody
    @RequestMapping("/list")
    public R selectImgList(@LoginUser User user,
                           @RequestParam(value = "page",defaultValue = "1")Integer page){
        List<Img> list = imgMapper.selectList(new QueryWrapper<Img>().eq(Img.COL_STATUS, 1));
        list.forEach(data->{
            data.setUrl(path+data.getUrl());
        });
        return R.ok().put("list",list);
    }

}
